package io.renren.modules.wx.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.wx.entity.TeacherEntity;
import io.renren.modules.wx.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;


/**
 * @author linmingze
 * @email ${email}
 * @date 2022-10-14 19:06:40
 */
@RestController
@RequestMapping("wx/teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = teacherService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{teacherId}")
    public R info(@PathVariable("teacherId") Integer teacherId) {
        TeacherEntity teacher = teacherService.getById(teacherId);

        return R.ok().put("teacher", teacher);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TeacherEntity teacher) {
        teacher.setAddTime(new Date());
        teacherService.save(teacher);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TeacherEntity teacher) {
        teacherService.updateById(teacher);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] teacherIds) {
        teacherService.removeByIds(Arrays.asList(teacherIds));
        return R.ok();
    }

}
